<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>行程交通配置信息</title>
    <script src="__PUBLIC__/jquery/jquery.min.js"></script>
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"  media="all">
    <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all" />
    <link rel="stylesheet" href="__CSS__/admin.css"  media="all">
    <link rel="stylesheet" href="__PUBLIC__/layui/css/eleTree.css" media="all">
    <style>
        .layui-icon-ok:before {
            content: "\e605";
        }
        .carPriceCurrencyTitle{
            line-height: 40px;
            float: left;
            margin-right: 4px;
        }
    </style>
</head>
<style>
    /*.page1{*/
    /*display: none;*/
    /*}*/
    .layui-input-block{
        /*margin-left: 40px;*/
    }
    .searchs{
        position: absolute;
        right: 200px;
    }
    .travel_list{
        height:200px;
        margin-left: 30px;
        margin-right: 30px;
        overflow-y: scroll;
    }

    .travel_tit{
        margin-left: 30px;
        margin-right: 30px;
    }
    .layui-table thead tr{
        background: #e6e6e6;
    }
    .page4-box{
        padding: 12px 16px;
    }
    .query-box{
        padding:20px 20px 10px 20px ;
        /*padding-top:20px;*/
        border: 1px solid #e6e6e6;
        min-height: 45px;
    }
    .selected_trip{
        border: 1px solid #e6e6e6;
    }
    .tripspan{
        margin-left: 40px;
        margin-right: 30px;
    }
    .tripspan span{
        line-height: 38px;
        background: #00a0e9;
        padding: 5px;
        border-radius: 10px;
        color: #fff;
    }
    .tag{
        float: left;
    }
    /*上一步下一步按钮居中*/
    .butcent{
        position: absolute;
        bottom: 20px;
        left: 40%;
        margin-left: 30%;
        width:20%;
        /*margin: 30px;*/
        padding: 30px;
    }

    .butcent2{
        margin-left: 70%;
        width:20%;
        padding: 30px;
    }

    .picturebut{
        /*background-color: #fbfdff;*/
        border: 1px solid #c0ccda;
        border-radius: 6px;
        box-sizing: border-box;
        font-size:22px;
        width:48%;
        height: 100%;
        margin-top:-10%;
        margin-left:-8%;
        cursor: pointer;
        line-height: 300px;
        vertical-align: top;
    }
    .page3{
        margin-left: 16%;
        margin-top: 20%;
    }
    .layui-form-select .layui-edge{
        display: none;
        right: 0;
    }
    th{
        text-align: left;
    }
    .layui-input{
        border-radius: 5px;
    }

    .box{
        margin-top:20px;
        margin-bottom:10px;
    }
    .section_title{
        line-height: 40px;
    }
    .eleTree-checkbox-disabled i{
        background-color:#9e9e9e !important;
    }
</style>
<body>
<script>
    //获取提示
    function showTransTips(id) {
        layer.tips("点击下方链接\n可查看详细包车类型", "#"+id+"", {
            tips: [1, "#1E9FFF"]
        });
    }
</script>
<!--客户信息的弹窗的内容数据-->
<div style="padding: 20px; background-color: #F2F2F2;">
    <div class="layui-row layui-col-space15">
        <!--行程交通配置信息-->
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">
                    <h2 style="width:95%;float: left;">4、派单成本配置</h2>
                    <div style="width:5%;float: right;">
                        <button class="layui-btn layui-btn-normal layui-btn-sm" id="jump">跳过</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">
                    <h2>1）车型配置</h2>
                </div>
                <div class="layui-card-body">
                    <div class="box">
                        <div style="margin-left:20px;">
                            <div class="layui-form-item">
                                <label class="layui-form-label">车型：</label>
                                <div class="layui-input-inline">
                                    <select class="layui-select setTransport" name="carTypeList" style="width:200px;">
                                        <option value="">请选择车型</option>
                                        {foreach name="carTypeList" item="car_v"}
                                        <option value="{$car_v.cartype_id}">{$car_v.title}</option>
                                        {/foreach}
                                    </select>
                                </div>
                                <div class="layui-input-inline" style="margin-left:10px;">
                                    <a class="layui-btn layui-btn-danger addCarType">添加</a>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label"></label>
                                <div class="layui-input-inline" id="carTypeIdList" style="width:60%;background: #eee;min-height:40px;">
                                    {volist name='carTypePriceList' id='car_value'}
                                    <span class="layui-btn layui-btn-sm layui-btn-normal delCarType" data-id="{$key}" style="margin: 5px">{$car_value}<i class="layui-icon"></i></span>
                                    {/volist}
                                </div>
                                <input type="hidden" name="carTypeIds" value="{notempty name='$trip.section_price_cartype'}{$trip.section_price_cartype}{/notempty}">
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!--行程交通配置信息-->
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header">
                        <h2>2）行程段落配置</h2>
                    </div>
                    <div class="layui-card-body">
                        <div class="box">
                            <div class="layui-form-item" style="margin-top:20px;">
                                <label class="layui-form-label"></label>
                                <div class="layui-input-inline" style="width:1200px;">
                                    <p style="color: red;"><i class="layui-icon" style="margin-right:8px;">&#xe702;</i>请按顺序从上至下设置分段，否则会出现错位的情况。如果发现设置出现问题，请清空分段数据后重新设置。如果需要<span style="color:green">【手工设置分段】</span>，也需要清空分段数据</p>
                                </div>
                            </div>
                            <div id="setSectionBody" style="display: {if $hasNotDisabled}block{else}none{/if};">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">司导分段：</label>
                                    <div class="layui-input-inline" style="width:600px;padding:4px 0">
                                        <a class="layui-btn layui-btn-sm" id="setSection" href="javascript:void(0)">提交司导分段</a>
                                    </div>
                                </div>
                                <div class="layui-form-item" style="padding-bottom: 8px;">
                                    <label class="layui-form-label"></label>
                                    <div class="layui-input-inline">
                                        <div class="eleTree ele1" lay-filter="mytree"></div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item" style="padding-bottom: 10px;">
                                <!--<label class="layui-form-label">分段项：</label>-->

                                <div style="width: 80%">
                                    {notempty name='$sectionList'}
                                    <table class="layui-table"  lay-even="" lay-skin="line" style="margin-left:110px;">
                                        <colgroup>
                                            <col width="20%">
                                            <col width="40%">
                                            <col width="40%">
                                        </colgroup>
                                        <thead>
                                        <tr>
                                            <th>司导</th>
                                            <th>名称</th>
                                            <th><i id="transportTips" onmouseover="showTransTips('transportTips')"  class="layui-icon" style="margin-right:8px;">&#xe702;</i>包车详情</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        {volist name='sectionList' id='value'}
                                        <tr>
                                            <td>第{$key+1}位司导</td>
                                            <td>
                                                <a class="section_title">{$value.dayTitle}</a>
                                            </td>
                                            <td>
                                                <a class="showSectionTransport" href="{:url('/admin/product/setsectiontransport',['id'=>$trip['id'],'index'=>$key])}"  style="border:0px;text-decoration:underline;color: blue;">
                                                    {if isset($value['transport'])&&!empty($value['transport'])}
                                                    {$value.transport}
                                                    {else}
                                                    <span style="color:#03a9f4;">暂未配置</span>
                                                    {/if}
                                                </a>
                                            </td>
                                        </tr>
                                        {/volist}
                                        </tbody>
                                    </table>
                                    {/notempty}
                                    <br>

                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label"></label>
                                <div class="layui-input-inline" style="width:600px;padding:4px 0">
                                    <a class="layui-btn layui-btn-sm layui-btn-danger" id="delAllSection" href="javascript:void(0)">清空分段数据</a>
                                </div>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!--设置价格-->
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">
                    <h2>3）设置成本</h2>
                </div>
                <div class="layui-card-body">
                    <div class="box">
                        <!--<div class="layui-form-item">-->
                            <!--<label class="layui-form-label"></label>-->
                            <!--<div class="layui-input-inline" style="width:80%;">-->
                                <!--<a class="layui-btn layui-btn-sm" id="setSectionPrice" href="javascript:void(0)">设置价格</a>-->
                                <!--<a class="layui-btn layui-btn-sm" id="getOrderPrice" href="javascript:void(0)" style="display:none;">查看订单核价</a>-->
                            <!--</div>-->
                        <!--</div>-->
                        <div id="showPriceResult" style="display:none;">
                            <div class="layui-form-item" style="margin-top:15px;">
                                <label class="layui-form-label">设置结果：</label>
                                <div class="layui-input-inline" style="width:200px;">
                                    <a class="layui-btn layui-btn-sm" id="getOrderPrice" href="javascript:void(0)" style="display:none;">核价</a>
                                    <input type="hidden" name="carPriceCurrency" value='{notempty name="$standardtrip.costCurrency"}{$standardtrip.costCurrency}{/notempty}'>
                                    <!--<select class="layui-select" name="carPriceCurrency">-->
                                        <!--<option value="">请选择派单价单位</option>-->
                                        <!--<option value="USD" {notempty name="$standardtrip.costCurrency"}{if $standardtrip.costCurrency=='USD'}selected{/if}{/notempty}>美元</option>-->
                                        <!--<option value="CAD" {notempty name="$standardtrip.costCurrency"}{if $standardtrip.costCurrency=='CAD'}selected{/if}{/notempty}>加元</option>-->
                                        <!--<option value="CNY" {notempty name="$standardtrip.costCurrency"}{if $standardtrip.costCurrency=='CNY'}selected{/if}{/notempty}>人民币</option>-->
                                    <!--</select>-->
                                </div>
                            </div>
                            <div class="layui-form-item" id="priceResult">

                            </div>

                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn layui-btn-radius" id="section_prev">上一页</button>
                                    <button class="layui-btn layui-btn-radius submitSectionPrice" lay-submit lay-filter="source">下一页</button>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item" style="margin-bottom:100px">
                        </div>

                        <div style="display:none" id="priceDetails">
                            <table class="layui-table" lay-even="" lay-skin="line" style="">
                                <thead>
                                <tr>
                                    <th>标题</th>
                                    <th>详情</th>
                                </tr>
                                </thead>
                                <tbody id="detailsBody">
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="__PUBLIC__/layui/layui.js"></script>
<script src="__PUBLIC__/jquery/jquery.min.js"></script>
</body>
</html>

<script>
    layui.config({
        base : '__PUBLIC__/layui/lay/modules/'
    }).extend({
        selectM: '../../../multiple/selectM',
    }).use(['layer','form','jquery','selectM','laydate','table','eleTree'],function() {
        var layer = layui.layer,
            $ = layui.jquery,
            form = layui.form,
            selectM = layui.selectM,
            laydate = layui.laydate,
            table = layui.table;
        eleTree = layui.eleTree;
        laydate.render({     //创建时间选择框
            elem: '#start_go_time' //指定元素
            , format: 'yyyy-MM-dd'
        });
        $(".showSectionTransport").click(function(){
            var url = $(this).attr('href');
            layer.open({
                type:2,
                content:url,
                area: ['80%', '80%'],
                btn:['关闭'],
                end:function(){
                    location.reload();
                }
            });
            return false;
        });

        $(document).on("click",".showPriceDetails",function(){
            var details_str = $(this).attr("data-details");
            var details_json = JSON.parse(details_str);
            var str = "";
            var index_arr = ["totalAmount","distance","duration","baseAmount","oilFee","exceedKMFee","overtimeFee","hotelFee","dinnerFee","parkingFee","nightFee","assistanceFee","childSeatFee"];
            var title_arr = ['总价','距离','时间','基础费用','油费','超出基础里程费用','超时费','司导酒店费用','餐补','停车费','夜间服务费','陪护费用，导游费用','儿童座椅'];
            $.each(details_json,function(i,v){
                $.each(v,function(ii,vv){
                    str += "<tr>";
                    str += "<td>"+vv.displayString+"</td>";
                    var info = "";
                    $.each(vv,function(info_i,info_v){
                        if($.inArray(info_i,index_arr)>-1){
                            var index=$.inArray(info_i,index_arr);
                            if($.inArray(info_i,['distance','duration'])==-1){
                                currency = getCurrencyTitle(vv.currency);
                            }else{
                                currency = "";
                            }
                            info += title_arr[index]+":"+currency+info_v+"<br>";
                        }
                    });
                    str += '<td>'+info+'</td>';
                    str += "</tr>";
                })
            });

            $("#detailsBody").html(str);
            layer.open({
                type: 1,
                area: ['50%', '50%'],
                btn: ['关闭'],
                content: $('#priceDetails'),
                yes: function(index, layero) {
                    layer.close(index);
                }
            })
        });
        var allData = {$schedules|json_encode};
        var tree ;
        var selectDayData = [];
        var selectItemData = [];
        //expandChild 是否可展开子节点 expandAll是否默认展开所有
        function rendEleTree(data,expandChild=true,expandAll=false) {
            tree = eleTree.render({
                elem: '.ele1',
                data: data,
                // data: [{'id':1,'label':'测试测试','disabled':false,'child':[]}],
                showCheckbox: true,
                expandOnClickNode: expandChild,
                defaultExpandAll:expandAll
            });
        }
        // 节点点击事件
        eleTree.on("nodeClick(mytree)",function(d) {
            //console.log(d.data);
        });
        // input被选中事件
        eleTree.on("nodeChecked(mytree)",function(d) {
            if(d.data.index.length>1){
                //记录选中的数值
                var p_index = d.data.index[0];
                var i_index = d.data.index[1];
                var val = p_index+'-'+i_index;
                if($.inArray(val,selectItemData)==-1 && d.isChecked){
                    selectItemData.push(val);
                    if($.inArray(p_index,selectDayData)){
                        selectDayData.push(p_index);
                    }
                }else if(!d.isChecked){
                    selectItemData.splice($.inArray(val,selectItemData),1);
                }
            }else{
                var p_index = d.data.index[0];
                if($.inArray(p_index,selectDayData)==-1 && d.isChecked){
                    selectDayData.push(p_index);
                    //增加子节点
                    var child_num = d.data.currentData.children.length;
                    for (var i=0;i<child_num;i++){
                        var val = p_index+"-"+i;
                        if($.inArray(val,selectItemData)==-1){
                            selectItemData.push(val);
                        }
                    }
                }else if(!d.isChecked){
                    selectDayData.splice($.inArray(p_index,selectDayData),1);
                    //删除子节点
                    var child_num = d.data.currentData.children.length;
                    for (var i=0;i<child_num;i++){
                        var val = p_index+"-"+i;
                        selectItemData.splice($.inArray(val,selectItemData),1);
                    }
                }
            }
        });
        //开启/禁止父级选择
        function changeDayDisabled(data,type=true){
            if(data.length<1){
                return [];
            }else{
                $.each(data,function(i,v){
                    data[i].disabled = type;
                })
            }

            return data;
        }
        //根据子集决定父级是否可选
        function disabledParentByChild(data){
            if(data.length<1){
                return [];
            }else{
                $.each(data,function(i,v){
                    var childChecked = false;
                    $.each(v.children,function(c_i,c_v){
                        if(c_v.disabled){
                            childChecked = true;
                        }
                    });
                    data[i].disabled = childChecked;
                })
            }
            return data;
        }

        form.on('select(traffic_type)',function(data){
            var tans_type = data.value;
            selectItemData = [];
            selectDayData = [];
            treeData = changeDayDisabled(allData,true);
            treeData = disabledParentByChild(treeData);
            rendEleTree(treeData,true);
        });
        rendEleTree(allData,true);
        $("#createTransport").click(function(){
            var trip_id = {$trip['id']};
            var trans_type = $("select[name=traffic_type]").val();
            if($.inArray(trans_type,['1','2','3','4','5','6','8'])==-1){
                layer.msg("请选择交通类型");return false;
            }
            if(selectItemData.length<1 || selectDayData.length<1){
                layer.msg("请选择交通所涵盖的天数及POI");return false;
            }
            console.log({trip_id:trip_id,trans_type:trans_type,days:selectDayData,items:selectItemData})
            $.post("/admin/product/createMoreTransport",{trip_id:trip_id,trans_type:trans_type,days:selectDayData,items:selectItemData},function(data){
                layer.msg(data.msg)
                if(data.code==1){
                    setTimeout(function(){
                        window.location.reload();
                    },1000)
                }
            },'json')
        });
        $("#setSection").click(function(){
            var trip_id = {$trip['id']};
            if(selectDayData.length<1 || selectItemData.length<1){
                layer.msg("请先选择节点！");return false;
            }
            $.post("/admin/product/setProductSection",{trip_id:trip_id,days:selectDayData,items:selectItemData},function(data){
                layer.msg(data.msg);
                if(data.code==1){
                    setTimeout(function(){
                        window.location.reload();
                    },1000)
                }
            },'json')
        });
        $(".delTransport").click(function(){
            var trip_id = {$trip['id']};
            var key = $(this).attr("data-id");

            $.post("/admin/product/delTransport",{id:trip_id,key:key},function(data){
                layer.msg(data.msg);
                if(data.code==1){
                    setTimeout(function(){
                        window.location.reload();
                    },1000)
                }
            },'json')
        });
        $("#delAllSection").click(function(){
            layer.confirm("您确定清空所有的分段数据，进行手工分段吗？",function(index){
                var trip_id = {$trip['id']};
                $.post("/admin/product/delAllSection",{id:trip_id},function(data){
                    layer.msg(data.msg);
                    if(data.code==1){
                        setTimeout(function(){
                            window.location.reload();
                        },1000)
                    }
                },'json')
            })
        });
        $("#batchTransport").click(function(){
            var trip_id = {$trip['id']};
            var trans_arr = [];
            var list = $(".setTransport");
            $.each(list,function(i,v){
                var key = $(v).attr("data-key");
                var value = $(v).val();
                if(value!="" && value!=undefined){
                    trans_arr.push({key:key,transport:value});
                }
            });
            if(trans_arr.length<1){
                layer.msg("请设置相应的包车类型");return false;
            }
            var trans_json = JSON.stringify(trans_arr);
            $.post("/admin/product/setTransportInSection",{id:trip_id,trans_arr:trans_json},function(data){
                layer.msg(data.msg);
                if(data.code==1){
                    setTimeout(function(){
                        window.location.reload();
                    },1000)
                }
            },'json')
        });
        //添加车辆类型
        $(".addCarType").click(function(){
            var value = $("select[name=carTypeList]").val();
            if(value=="" || value=='0' || value==undefined){
                layer.msg("请选择车型");return false;
            }
            var value_name = $("select[name=carTypeList]").find('option:selected').text();
            var carTypeIds = $("input[name=carTypeIds]").val();
            if(carTypeIds!=""){
                carTypeIds_arr = carTypeIds.split(",");
                if($.inArray(value,carTypeIds_arr)>-1){
                    layer.msg("请勿重复添加");
                    return false;
                }else{
                    carTypeIds_arr.push(value);
                    carTypeIds = carTypeIds_arr.join(',');
                }
            }else{
                carTypeIds = value;
            }
            $("input[name=carTypeIds]").val(carTypeIds);
            //添加新的车辆类型
            addNewCarTypeNode({id:value,name:value_name});
            //渲染表格
            showPriceTable();
        });

        function addNewCarTypeNode(item){
            var str = "";
            str += '<span class="layui-btn layui-btn-sm layui-btn-normal delCarType" data-id="'+item.id+'" style="margin: 5px">'+item.name+'<i class="layui-icon"></i></span>';
            $("#carTypeIdList").append(str);
        }
        //删除车辆类型
        $(document).on("click",'.delCarType',function(){
            var that = this;
            var value = $(this).attr("data-id");
            var carTypeIds = $('input[name=carTypeIds]').val();
            if(carTypeIds.length>0){
                carTypeIds_arr = carTypeIds.split(",");
                carTypeIds_arr.splice($.inArray(value,carTypeIds_arr),1);
                if(carTypeIds_arr.length>0){
                    carTypeIds = carTypeIds_arr.join(',');
                }else{
                    carTypeIds = "";
                }

                $('input[name=carTypeIds]').val(carTypeIds);
                $(that).remove();
                //渲染表格
                showPriceTable();
            }else{
                layer.msg("至少需要配置一个车型");
                //渲染表格
                showPriceTable();
                return false;
            }
        });
        //获取订单核价
        $("#getOrderPrice").click(function(){
            var carTypeIds = $("input[name=carTypeIds]").val();
            if(carTypeIds.length<1){
                layer.msg("请先添加车型！");return false;
            }
            var trip_id = {$trip['id']};
            var getorderprice_loading = layer.load(1);
            var carPriceCurrency = "";
            $.post("/admin/product/getProductSectionPriceByCarType",{id:trip_id,carType:carTypeIds},function(data){
                layer.close(getorderprice_loading);
                layer.msg(data.msg);
                if(data.code==1){
                    $.each(data.data,function(i,v){
                        var res_cartype = v.type;
                        var res_section = v.section_json;
                        $.each($(".orderPrice_"+res_cartype),function (price_k,price_v) {
                            var currency = getCurrencyTitle(res_section[price_k].currency);
                            if(carPriceCurrency==""){
                                $("input[name=carPriceCurrency]").val(res_section[price_k].currency);
                                $(".carPriceCurrencyTitle").text(currency);
                            }
                            $(price_v).text(currency+res_section[price_k].totalAmount);
                            var detail = res_section[price_k].amountDetails;
                            var detail_json = JSON.stringify(detail);
                            var html = "<a class='showPriceDetails' style='color:#1E9FFF;font-size: 12px;' data-details='"+detail_json+"'>显示详情</a>";
                            $(this).next().html(html);
                            var selfPrice = $(this).next().next().find("input[name=selfPrice]").val();
                            if(selfPrice=="" || selfPrice==undefined){
                                $(this).next().next().find("input[name=selfPrice]").val(res_section[price_k].totalAmount)
                            }
                        })
                    })
                }
            },'json')
        });
        //设置价格
        $("#setSectionPrice").click(function(){
            showPriceTable();
        });

        //上一页   基础数据页
        $("#section_prev").click(function(){
            location.href = "{:url('admin/standard/savebasic',['id'=>$standardtrip['sid']])}";
            return false;
        });

        //跳过
        $("#jump").click(function(){
            location.href = "{:url('admin/standard/savegoods',['id'=>$standardtrip['sid']])}";
            return false;
        });

    });
    //获取币种的标识
    function getCurrencyTitle(currency) {
        switch (currency) {
            case "USD":
                return "$";
            case "CAD":
                return "C$";
            case "CNY":
                return "¥";
            default:
                return "";
        }
    }
    //获取分段的标题
    function getSectionTitle() {
        var title = [];
        $.each($(".section_title"),function(i,v){
            title.push($(v).text());
        });
        return title;
    }
    //渲染表格
    function renderTableData(i,item,title,carPriceCurrencyTitle){
        var str = "";
        str = '<div class="layui-input-inline" style="width:1000px;margin-left: 110px;">\n' +
            '                    <!--包车展示-->\n' +
            '                    <table class="layui-table" lay-even="" lay-skin="line" style="margin-bottom:20px;">\n' +
            '                        <colgroup>\n' +
            '                            <col width="10%" align="center">\n' +
            '                            <col width="45%" align="center">\n' +
            '                            <col width="15%" align="center">\n' +
            '                            <col width="15%" align="center">\n' +
            '                            <col width="15%" align="center">\n' +
            '                        </colgroup>\n' +
            '                        <thead>\n' +
            '                        <tr><td colspan="5" style="text-align: center;font-size:18px;font-weight: bold;">'+item.carTypeTitle+'</td></tr><tr>\n' +
            '                            <th>司导</th>\n' +
            '                            <th>负责行程概览</th>\n' +
            '                            <th>核价价格</th>\n' +
            '                            <th>核价详情</th>\n' +
            '                            <th>预估销售成本</th>\n' +
            '                        </tr>\n' +
            '                        </thead>\n' +
            '                        <tbody>\n';
        $.each(title,function(i_title,v_title){
            str += '                        <tr>\n' +
                '                            <td>第'+(i_title+1)+'位司导</td>\n' +
                '                            <td>\n' +
                '                                '+v_title+'\n' +
                '                            </td>\n' +
                '                            <td class="orderPrice_'+item.car_type+'">\n' +
                '                            </td>\n' +
                '                            <td>\n' +
                '                            </td>\n' +
                '                            <td>\n' +
                '                                <span class="carPriceCurrencyTitle">'+carPriceCurrencyTitle+'</span><input type="text" data-id="'+item.car_type+'" class="layui-input layui-input-inline" style="width:70%" name="selfPrice" placeholder="请填写报价" value="'+(item.price[i_title]||"")+'">\n' +
                '                            </td>\n' +
                '                        </tr>\n';
        });

        str+='                        </tbody>\n' +
            '                    </table>\n' +
            '                </div>';

        return str;
    }
    //渲染设置价格的表格
    function renderSectionPriceData(data,carPriceCurrencyTitle){
        var title = getSectionTitle();
        var str = "";
        $.each(data,function(i,v){
            str += renderTableData(i+1,v,title,carPriceCurrencyTitle);
        });

        $("#priceResult").children().remove();
        $("#priceResult").append(str);
    }
    //最终   保存价格   下一页
    $(".submitSectionPrice").click(function(){
        var trip_id = {$trip['id']};
        var carTypeData = $("input[name=carTypeIds]").val();
        if(carTypeData.length<1){
            layer.msg("请先选择车型！");return false;
        }else{
            carTypeData = carTypeData.split(",");
        }
        var priceList = $("input[name=selfPrice]");
        if(priceList.length<1){
            layer.msg("请先设置价格！");
            return false;
        }
        var priceData = [];
        var error = 0;
        $.each(priceList,function(i,v){
            var carType = $(v).attr("data-id");
            var value = $(v).val();
            if(value=="" || value==undefined){
                layer.msg("请填写所有的派单价！");
                error = 1;
                return false;
            }
            priceData.push({carType:carType,value:value});
        });

        if(error==1){
            return false;
        }

        var carPriceData = [];
        $.each(carTypeData,function(car_i,car_v){
            var carPrice ={'car_type':car_v,'price':[]};
            $.each(priceData,function(i,v){
                if(v.carType==car_v){
                    carPrice.car_type=car_v;
                    carPrice.price.push(v.value);
                }
            });
            carPriceData.push(carPrice);
        });
        //检查派单价单位
        var currency = $("input[name=carPriceCurrency]").val();
        if(currency=="" || currency==undefined){
            layer.msg("请先核价！");
            return false;
        }
        $.post("/admin/product/saveProductSectionPriceData",{id:trip_id,carPriceData:carPriceData,currency:currency,page_index:5},function(res){
            layer.msg(res.msg);
            if(res.code == 1) {
                setTimeout(function(){
                    location.href = "{:url('admin/standard/savegoods',['id'=>$standardtrip['sid']])}";
                },1500);
            }
            return false;
        },'json')
    });

    //渲染价格表格
    function showPriceTable(){
        var setPriceLoading = layer.load(1);
        var trip_id = {$trip['id']};
        var carTypeIds = $("input[name=carTypeIds]").val();
        var carPriceCurrency = $("input[name=carPriceCurrency]").val();
        var carPriceCurrencyTitle = getCurrencyTitle(carPriceCurrency);
        if(carTypeIds.length<1){
            layer.msg("请选择车型");
            $("#showPriceResult").hide();
            $("#getOrderPrice").hide();
            layer.close(setPriceLoading);
            return false;
        }else{
            $.post("/admin/product/setSectionPriceData",{trip_id:trip_id,carTypeIds:carTypeIds},function(res){
                layer.close(setPriceLoading);
                if(res.code==1){
                    renderSectionPriceData(res.data,carPriceCurrencyTitle);
                    $("#showPriceResult").show();
                    $("#getOrderPrice").show();
                }else{
                    layer.msg(res.msg);
                    return false;
                }
            },'json')
        }
    }

    window.onload = function() {
        showPriceTable();
    };
</script>
